﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using ShapeDemo.UC.WinProp;
using System.Windows;
using System.Windows.Input;

namespace ShapeDemo
{
    public class PointDrawer
    {
        public Canvas PointCanvas { get; set; }
        public List<ASPNETX_WPFPoint> PointCollection { get; set; }

        private WinPropPoint winPointProp;
        private WinPropCommon winCommonProp;

        ASPNETX_WPFPoint pointBody;
        private TMouse _MouseType;

        public PointDrawer(Canvas canvasContent,  WinPropPoint winShapeProp,WinPropCommon winProp)
        {
            PointCollection = new List<ASPNETX_WPFPoint>();
            
            PointCanvas = canvasContent;
            //PointCollection = lstShape;
            winPointProp = winShapeProp;
            winCommonProp = winProp;

            _MouseType = TMouse.Drawing;

            PointCanvas.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(pointCanvas_MouseLeftButtonDown);
            PointCanvas.MouseMove += new System.Windows.Input.MouseEventHandler(pointCanvas_MouseMove);

            BindListBox();
        }

        public void Draw()
        { 
            
        }

        
        #region 画点
        private void pointCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (_MouseType == TMouse.Drawing)
            {
                Point p = e.GetPosition(PointCanvas);

                pointBody = new ASPNETX_WPFPoint();

                pointBody.CommonProperty.Index = winCommonProp.tbIndex.Text;
                pointBody.CommonProperty.Content = winCommonProp.tbContent.Text;

                pointBody.PointBody = p;
                PointCanvas.Children.Add(pointBody.DrawPoint());

                PointCollection.Add(pointBody);

                BindListBox();
            }
        }

        private void pointCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (_MouseType == TMouse.Drawing)
            {
                Point p = e.GetPosition(PointCanvas);
                winPointProp.X = p.X;
                winPointProp.Y = p.Y;
            }
        }
        #endregion

        /// <summary>
        /// 绑定各层所添加的图形到列表
        /// </summary>
        public void BindListBox()
        {
            winCommonProp.lstHistory.Items.Clear();
            foreach (ASPNETX_WPFPoint item in PointCollection)
            {
                winCommonProp.lstHistory.Items.Add(item.CommonProperty.Content);
            }
        }
    }
}
